package com.hzp.micromall.common.core.api;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author houzipeng
 * @Date 2022/1/28 22:30
 * @Version 1.0
 * 响应码枚举类
 */
public enum ResultCode implements IErrorCode {
    SUCCESS(true,200, "操作成功"),
    FAILED(false, 500, "操作失败"),

//    Admin_ERROR(0001, "用户端错误"),
//    Admin_LOGIN_ERROR(0200, "用户登录异常"),
//
    USER_NOT_EXIST(false ,101, "用户不存在"),
    USER_ACCOUNT_LOCKED(false, 102, "用户账户被冻结"),
    USER_ACCOUNT_EXPIRED(false,103, "用户账户已过期"),
    USER_ACCOUNT_DISABLED(false, 104, "用户账户已禁用"),
    USER_ACCOUNT_ALREADY_EXISTS(false, 105, "用户名已存在"),
    USERNAME_OR_PASSWORD_ERROR(false, 106, "用户名或密码错误"),
    USER_ACCOUNT_OLD_PASSWORD_ERROR(false, 107, "用户原密码错误"),
    PASSWORD_ENTER_EXCEED_LIMIT(false,108, "用户输入密码次数超限"),
    CLIENT_AUTHENTICATION_FAILED(false, 109, "客户端认证失败"),
    TOKEN_INVALID_OR_EXPIRED(false, 110, "暂未登录或token已过期"),
    TOKEN_ACCESS_FORBIDDEN(false, 111,"token已被禁止访问"),

    AUTHORIZED_ERROR(false, 112, "访问权限异常"),
    ACCESS_UNAUTHORIZED(false,113, "访问未授权");
//    FORBIDDEN_OPERATION(0302, "演示环境禁止修改、删除重要数据，请本地部署后测试"),
//
//
//    PARAM_ERROR(0400, "用户请求参数错误"),
//    RESOURCE_NOT_FOUND(0401, "请求资源不存在"),
//    PARAM_IS_NULL(0410, "请求必填参数为空"),
//
//    Admin_UPLOAD_FILE_ERROR(0700, "用户上传文件异常"),
//    Admin_UPLOAD_FILE_TYPE_NOT_MATCH(0701, "用户上传文件类型不匹配"),
//    Admin_UPLOAD_FILE_SIZE_EXCEEDS(0702, "用户上传文件太大"),
//    Admin_UPLOAD_IMAGE_SIZE_EXCEEDS(0703, "用户上传图片太大"),
//
//    SYSTEM_EXECUTION_ERROR(0001, "系统执行出错"),
//    SYSTEM_EXECUTION_TIMEOUT(0100, "系统执行超时"),
//    SYSTEM_ORDER_PROCESSING_TIMEOUT(0100, "系统订单处理超时"),
//
//    SYSTEM_DISASTER_RECOVERY_TRIGGER(0200, "系统容灾功能被触发"),
//    FLOW_LIMITING(0210, "系统限流"),
//    DEGRADATION(0220, "系统功能降级"),
//
//    SYSTEM_RESOURCE_ERROR(0300, "系统资源异常"),
//    SYSTEM_RESOURCE_EXHAUSTION(0310, "系统资源耗尽"),
//    SYSTEM_RESOURCE_ACCESS_ERROR(0320, "系统资源访问异常"),
//    SYSTEM_READ_DISK_FILE_ERROR(0321, "系统读取磁盘文件失败"),
//
//    CALL_THIRD_PARTY_SERVICE_ERROR(0001, "调用第三方服务出错"),
//    MIDDLEWARE_SERVICE_ERROR(0100, "中间件服务出错"),
//    INTERFACE_NOT_EXIST(0113, "接口不存在"),
//
//    MESSAGE_SERVICE_ERROR(0120, "消息服务出错"),
//    MESSAGE_DELIVERY_ERROR(0121, "消息投递出错"),
//    MESSAGE_CONSUMPTION_ERROR(0122, "消息消费出错"),
//    MESSAGE_SUBSCRIPTION_ERROR(0123, "消息订阅出错"),
//    MESSAGE_GROUP_NOT_FOUND(0124, "消息分组未查到"),
//
//    DATABASE_ERROR(0300, "数据库服务出错"),
//    DATABASE_TABLE_NOT_EXIST(0311, "表不存在"),
//    DATABASE_COLUMN_NOT_EXIST(0312, "列不存在"),
//    DATABASE_DUPLICATE_COLUMN_NAME(0321, "多表关联中存在多个相同名称的列"),
//    DATABASE_DEADLOCK(0331, "数据库死锁"),
//    DATABASE_PRIMARY_KEY_CONFLICT(0341, "主键冲突");


    private Boolean success;
    private Integer code;
    private String message;

    private ResultCode(Boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    @Override
    public Boolean success() {
        return success;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public static ResultCode getResultByCode(Integer code){
        Optional<ResultCode> codeOptional = Arrays.stream(ResultCode.values())
                .filter(item -> item.getCode().equals(code)).findFirst();
        return codeOptional.get();
    }
}
